package com.young.shop_admin.controller;

import com.young.shop_admin.pojo.entity.Order;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cancelOrder")
public class cancelOrderController extends BaseController{

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //跨域
        resp.setHeader("Access-Control-Allow-Origin","http://localhost:63342");

        //获取商品id
        Order order = convertParamsToEntity(req, Order.class);
        Integer id = order.getId();
        //通过id修改产品状态,调用services
        try {
            Order dbOrder = orderList.checkCancelOrder(id);
            writerSuccessResult(dbOrder,resp);
        }catch (RuntimeException e){
            String errorMsg = e.getMessage();
            writerErrorResult(errorMsg, resp);
        }
    }
}
